/**
 * Description:
 *
 * @author      Eden
 * @datetime    2016/12/10 11:01
 * @copyright   Beijing CmsTop Technology Co.,Ltd.
 */

(function () {

    var api = {
        getDaysUrl: '/order/setting/getDays',
        setDaysUrl: '/order/setting/setDays'
    };

    sm.controller('admin-order-setting', ['$scope', '$http', 'Modal', function ($scope, $http, Modal) {

        $scope.days = 0;
        $scope.getDays = function () {
            $http.get(api.getDaysUrl).success(function (res) {
                if (res.state) {
                    $scope.days = res.data;
                }
            });
        };

        $scope.setDays = function () {
            if ($scope.days <= 0) {
                Modal.error('自动完成天数请大于0天');
                return false;
            }

            $http.post(api.setDaysUrl, {days: $scope.days}).success(function (res) {
                if (res.state) {
                    Modal.success('设置成功');
                } else {
                    Modal.error(res.error ? res.error : '设置失败');
                }
            });
        };

        $scope.getDays();


    }]);
})();